#### Covid-19 Spillover Effects onto General Vaccine Attitudes
### Replication code - Over time vaccine hesitancy by COVID-19 vax status - Figures 2 and S6
### use file "wavesvgcl.csv"
### Kristin Lunz Trujillo

library(dplyr)
library(haven)
library(srvyr)
library(survey)
library(tidyr)
library(broom)
library(purrr)
library(ggplot2)
library(stargazer)
library(dotwhisker)
library(tibble)
library(xtable)
library(jtools)
library(Hmisc)
library(ggpubr)

## load data
waves1418_cl <- read.csv(".../wavesvgcl.csv")

table(wavesvgcl$vaccine_get)


# functions
vaxget_names <- list(
  '1'="One Dose",
  '2'="Two or More Doses",
  '3'="No Doses"
)
vaxget_lab <- function(variable,value){
  return(vaxget_names[value])
}


# make wave date labels and separate data frames by vaccine status
wavesvgcl$date <- factor(wavesvgcl$date, levels=c("Jun 21", "Nov 21", "Jan 22", "Mar 22"))

onevax <- wavesvgcl %>% filter(vaccine_get != 2)
onevax
twovax <- wavesvgcl %>% filter(vaccine_get == 2)
twovax


###################################################################################
## Figure: Vax hesitancy by partisanship, for those who got 2+ COVID vaccine doses (Figure 2)
twovax %>%
  filter(!is.na(vaxhes)) %>%
  filter(!is.na(pid3)) %>%
  ggplot(aes(date,vaxhes))+      
  stat_summary(geom = "line", fun = mean, position = "dodge") +
  stat_summary(geom = "point", fun = mean, position = "dodge") +
  stat_summary(fun.data = mean_cl_normal,  
               geom = "errorbar") +
  facet_wrap(~pid3) + 
  scale_y_continuous(name="General Vaccine Skepticism", limits=c(0, 8)) + xlab("") + theme_bw() +
  theme(legend.position="none") + ggtitle("Two+ COVID Vaccine Doses") + theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust=1, size=12), axis.title.y=element_text(size=12),
                                                                              strip.text.x = element_text(size = 14))


###################################################################################
## Figure: Vax hesitancy by partisanship, for those who got less than two COVID vaccine doses (Figure S6)
onevax %>%
  filter(!is.na(vaxhes)) %>%
  filter(!is.na(pid3)) %>%
  ggplot(aes(date,vaxhes))+      
  stat_summary(geom = "line", fun = mean, position = "dodge") +
  stat_summary(geom = "point", fun = mean, position = "dodge") +
  stat_summary(fun.data = mean_cl_normal,  
               geom = "errorbar") +
  facet_wrap(~pid3) + 
  scale_y_continuous(name="General Vaccine Skepticism", limits=c(0, 8)) + xlab("") + theme_bw() +
  theme(legend.position="none") + ggtitle("Less Than Two COVID Vaccine Doses") + theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust=1, size=12), axis.title.y=element_text(size=12),
                                                                                       strip.text.x = element_text(size = 14))








